﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace DynamicHeader
{
    /// <summary>
    /// Install filter which replaced DynamicHeader signature to realize HTML par request.
    /// </summary>
    public class DynamicHeaderModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
        }

        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            var context = sender as HttpApplication;
            if (context.Context.CurrentHandler is MvcHandler)
            {
                var orgFilter = context.Response.Filter;
                context.Response.Filter = new DynamicHeaderFilter(orgFilter);
            }
        }

        public void Dispose()
        {
        }
    }
}
